package com.rio.core;

import java.util.concurrent.CountDownLatch;

import android.test.AndroidTestCase;

public class BaseTestCase extends AndroidTestCase {
	
	private CountDownLatch latch ;
	
	@Override
	protected void setUp() throws Exception {
		BaseApplication.setContext(getContext());
		latch = new CountDownLatch(1);
		super.setUp();
		L.start();
	}

	@Override
	protected void tearDown() throws Exception {
		L.stop();
		super.tearDown();
	}
	
	/**
	 * 等待异步线程完成
	 */
	protected void await(){
		if(U.notNull(latch)){
			try {
				latch.await();
			} catch (InterruptedException e) {
				L.e(e);
			}
		} 
	}
	
	/**
	 * 异步线程完成时调用
	 */
	protected void finish(){
		if(U.notNull(latch)) latch.countDown();
	}
	
	
}
